package com.cyou.qb.face.util.converter;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;

public class FaceStringUtil {

	public static String createURLString(String urlString,Map<String, Object> map){

		if(map != null){
			StringBuffer param = new StringBuffer();
			int i = 0;
			for(String key:map.keySet()){
				if(map.get(key)==null)
					continue;
				if(i == 0){
					param.append("?");
				}else{
					param.append("&");
				}
				try {
					param.append(key).append("=").append(URLEncoder.encode(map.get(key).toString(),"UTF-8"));
				} catch (UnsupportedEncodingException e) {
				}
				i++;
			}
			urlString += param;
		}
		return urlString;
	}
	
	public static String createURLString(String urlString,Map<String, Object> map,String charset){

		if(map != null){
			StringBuffer param = new StringBuffer();
			int i = 0;
			for(String key:map.keySet()){
				if(map.get(key)==null)
					continue;
				if(i == 0){
					param.append("?");
				}else{
					param.append("&");
				}
				try {
					param.append(key).append("=").append(URLEncoder.encode(map.get(key).toString(),charset));
				} catch (UnsupportedEncodingException e) {
				}
				i++;
			}
			urlString += param;
		}
		System.out.println(urlString);
		return urlString;
	}
	
	public static String delSeparator(String jsonString){
		String newJsonString = "";
		//byte b[] = jsonString.getBytes();
		char b[] = jsonString.toCharArray();
		for(int i=0;i<b.length;i++){
			if(i>0 &&b[i] == '"'){
				if(b[i-1] =='\\'){
					b[i-1] = ' ';
				}
			}else{
				
			}
		}
		newJsonString = String.copyValueOf(b);
		return newJsonString;
	}
}
